import { Component, OnInit } from '@angular/core';
import {LoginAndregisterService} from '../login-andregister.service';
import { NzMessageService } from 'ng-zorro-antd/message';
import { Router} from '@angular/router'; //导入router服务
@Component({
  selector: 'app-login',
  templateUrl: './login.component.html',
  styleUrls: ['./login.component.css']
})
export class LoginComponent implements OnInit {

  constructor(private loginAndregisterService:LoginAndregisterService,private message: NzMessageService,private router :Router) { }
  email='';
  password='';
  judge(){
    if(this.email=='' || this.password==''){
      this.message.create('error','登录信息不能为空！');
    }else{
      this.login();
    }
  }
  login(){
    this.loginAndregisterService.submitLogin(this.email,this.password).subscribe(res=>{
      console.log("登录：",res)
      console.log(res.cookie)
      if(res.code==0){
        this.message.create('success','登录成功！');
        window.localStorage['username']=this.email;
        window.localStorage['password']=this.password;
        this.router.navigateByUrl('/home/movies');
      }else{
        this.message.create('error',res.msg);
      }
    })
  }
  ngOnInit(): void {

  }

}
